﻿using System.Data.Entity;

namespace Softelligent.Zintra.Synchronizations.ContactsExpressConsole.Entities
{
    public class ContactsCatalog : DbContext
    {
        public DbSet<Contact> Contacts { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Contact>()
                        .Property(c => c.UnformattedName)
                        .HasMaxLength(255);
            modelBuilder.Entity<Contact>()
                        .Property(c => c.FirstName)
                        .HasMaxLength(255);
            modelBuilder.Entity<Contact>()
                        .Property(c => c.LastName)
                        .HasMaxLength(255);
            modelBuilder.Entity<Contact>()
                        .Property(c => c.WorkEmailAddress)
                        .HasMaxLength(255);
            modelBuilder.Entity<Contact>()
                        .Property(c => c.HomeEmailAddress)
                        .HasMaxLength(255);
            modelBuilder.Entity<Contact>()
                        .HasOptional(c => c.Address)
                        .WithRequired()
                        .WillCascadeOnDelete();

            modelBuilder.Entity<Address>()
                        .Property(a => a.Street)
                        .HasMaxLength(255);
            modelBuilder.Entity<Address>()
                        .Property(a => a.PostalCode)
                        .HasMaxLength(255);
            modelBuilder.Entity<Address>()
                        .Property(a => a.City)
                        .HasMaxLength(255);
            modelBuilder.Entity<Address>()
                        .Property(a => a.State)
                        .HasMaxLength(255);
            modelBuilder.Entity<Address>()
                        .Property(a => a.Country)
                        .HasMaxLength(255);

            base.OnModelCreating(modelBuilder);
        }
    }
}
